package com.banyou.banyou.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.banyou.banyou.R;
import com.banyou.banyou.base.BaseActivity;
import com.bumptech.glide.Glide;

import java.util.List;

import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;


/**
 * ----------Dragon be here!----------/
 * 　　　┏┓　　　┏┓
 * 　　┏┛┻━━━┛┻┓
 * 　　┃　　　　　　　┃
 * 　　┃　　　━　　　┃
 * 　　┃　┳┛　┗┳　┃
 * 　　┃　　　　　　　┃
 * 　　┃　　　┻　　　┃
 * 　　┃　　　　　　　┃
 * 　　┗━┓　　　┏━┛
 * 　　　　┃　　　┃神兽保佑
 * 　　　　┃　　　┃代码无BUG！
 * 　　　　┃　　　┗━━━┓
 * 　　　　┃　　　　　　　┣┓
 * 　　　　┃　　　　　　　┏┛
 * 　　　　┗┓┓┏━┳┓┏┛
 * 　　　　　┃┫┫　┃┫┫
 * 　　　　　┗┻┛　┗┻┛
 * ━━━━━━神兽出没━━━━━━
 * 项目名称：WheelMedical
 * 包名:com.yyxk.wheelmedical.adapter
 * 类描述：
 * 创建人：Random
 * 创建时间：16:25
 * 修改人：Random
 * 修改时间：16:25
 * 修改备注：
 */
public class IllnessPicAdapter extends PagerAdapter {
    private List<String> mList;
    private Context mContext;
    private BaseActivity mActivity;//传入Activity的实例
    private View mLayoutView;//传入布局View
    private boolean mIsLayoutVie;
    PhotoView mPhotoView;
    public IllnessPicAdapter(List<String> mList, Context mContext, BaseActivity mActivity, View view, boolean mIsLayoutVie) {
        this.mList = mList;
        this.mContext = mContext;
        this.mActivity=mActivity;
        this.mLayoutView=view;
        this.mIsLayoutVie=mIsLayoutVie;
    }




    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        mPhotoView=new PhotoView(mContext);
        mPhotoView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        mPhotoView.setMaximumScale(5);
        Glide.with(mContext).load(mList.get(position)).placeholder(R.drawable.place_holder).into(mPhotoView);
        container.addView(mPhotoView);
        mPhotoView.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {
            @Override
            public void onViewTap(View view, float x, float y) {
                mIsLayoutVie=true;
                mActivity.setContentView(mLayoutView);
            }
        });
        return mPhotoView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(mPhotoView);
    }
}
